<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link :to="{path:'/cms/articleAdd',query:{categoryId:query.categoryId}}">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
          >新增</el-button>
        </router-link>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="articleList" @selection-change="handleSelectionChange">
      <el-table-column prop="title" label="文章标题" :show-overflow-tooltip="true" width="240"></el-table-column>
      <el-table-column prop="categoryCnName" label="所属栏目" width="240"></el-table-column>
      <el-table-column prop="createTime" label="发布时间" align="center" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="clicks" label="浏览量" align="center" width="160"></el-table-column>
      <el-table-column prop="weight" label="权重" align="center" width="160"></el-table-column>
      <el-table-column prop="status" label="发布状态" align="center" width="160"></el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link :to="{path:'/cms/articleAdd',query:{id:scope.row.id,categoryId:query.categoryId}}">
            <el-button
              size="mini"
              type="success"
              icon="el-icon-edit"
              style="margin: 0px 10px;width: 60px;"
            >修改</el-button>
          </router-link>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            style="margin: 0px 10px;width: 60px;"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {getArticleList} from "@/api/cms/article";

export default {
  name: "article",
  data() {
    return {
      query: {
        categoryId: ''
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 菜单表格树数据
      articleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部折叠
      isExpandAll: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        categoryId: undefined
      },
    }
  },
  created() {
    this.query.categoryId = this.$route.query.categoryId;
    this.getList();
  },
  methods:{
    getList() {
      this.loading = true;
      this.queryParams.categoryId = this.query.categoryId;
      getArticleList(this.queryParams).then(response => {
          this.articleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
  }
}
</script>

<style scoped>

</style>
